﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2014-04-08 14:15
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BassDrop.Core.Common.Options.Items;
using BassDrop.Core.Common.Services;

namespace BassDrop.Core.Common.Options
{
	/// <summary>
	/// Abstract base class for option lists. Contains the set of OptionsItems.
	/// </summary>
	public abstract class OptionsSetBase : INotifyPropertyChanged
	{
		/// <summary>
		/// The list of options in an enumerable. Will be layed out in this order.
		/// </summary>
		public IEnumerable<OptionsItemBase> Options
		{
			get
			{
				return OptionList.AsEnumerable();
			}
		}

		/// <summary>
		/// The list of options. Will be layed out in this order.
		/// </summary>
		protected List<OptionsItemBase> OptionList
		{
			get;
			private set;
		}

		/// <summary>
		/// The name of this options set
		/// </summary>
		public abstract string Name
		{
			get;
		}

		/// <summary>
		/// Constructs a new options set
		/// </summary>
		protected OptionsSetBase()
		{
			OptionList = new List<OptionsItemBase>();
		}

		/// <summary>
		/// Loads the options
		/// </summary>
		/// <param name="settings">the seettings object to load from</param>
		public abstract Task Load( ISettings settings );

		/// <summary>
		/// Saves the options
		/// </summary>
		/// <param name="settings">the seettings object to save to</param>
		public abstract void Save( ISettings settings );

		#region INotifyPropertyChanged Members

		/// <summary>
		/// Fired when the value of a property changes
		/// </summary>
		public event PropertyChangedEventHandler PropertyChanged;

		#endregion

		/// <summary>
		/// Fires a new property change event with the passed parameters
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnPropertyChanged( PropertyChangedEventArgs e ) // TODO: többi property is hívja
		{
			if ( PropertyChanged != null )
			{
				PropertyChanged( this, e );
			}
		}
	}
}
